package com.example.graphic.controller;

import com.example.graphic.constant.ErrorCodeEnum;
import com.example.graphic.model.vo.BaseResultVO;
import com.example.graphic.service.OssService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/os9999s")
@RestController
public class OssController {

    private static final Logger logger = LoggerFactory.getLogger(OssController.class);

    @Autowired
    private OssService ossService;

    @PostMapping("/upload")
    public BaseResultVO<List> uploadFile(@RequestParam("files") MultipartFile[] files) {
        // 调用服务方法上传文件
        Map<String, Object> result = new HashMap<>();
        List<String> fileUrls = ossService.uploadFiles(files);
        if (!fileUrls.isEmpty()) {
            result.put("fileUrls", fileUrls);
            return new BaseResultVO<>(ErrorCodeEnum.SUCCESS.getCode(), "文件批量上传成功", fileUrls);
        }
        return new BaseResultVO<>(ErrorCodeEnum.REQUEST_FAIL.getCode(), "文件上传失败");
    }
}